package com.eveinfo.display.setting;

import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.eveinfo.tools.Pilot;

public class PilotListAdapter extends BaseAdapter {

	private SettingCharacterView activity;
	private ArrayList<Pilot> pilots;

	public PilotListAdapter(SettingCharacterView activity, ListView listView, ArrayList<Pilot> pilots) {
		this.activity = activity;
		this.pilots = pilots;
		listView.setAdapter(this);
	}

	@Override
	public int getCount() {
		return pilots.size();
	}

	@Override
	public Object getItem(int position) {
		return pilots.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		TextView textView = new TextView(activity);
		textView.setTextSize(18);
		textView.setPadding(0, 0, 0, 5);
		textView.setText(pilots.get(position).getName());
		textView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				activity.setSelectedItem(position);
			}
		});

		return textView;
	}
	
	public void refreshData(ArrayList<Pilot> pilots){
		this.pilots = pilots;
		notifyDataSetChanged();
	}

}
